<template>
  <el-dialog :title="!dataForm.id ? '新增' : '修改'" :close-on-click-modal="false" :visible.sync="visible">
    <el-form :model="dataForm" ref="dataForm" @keyup.enter.native="dataFormSubmit()"
      label-width="100px">
      <el-form-item label="用户名称" prop="userName">
        <el-input v-model="dataForm.userName" placeholder="请输入用户名称" readonly></el-input>
      </el-form-item>
      <el-form-item label="服务名称" prop="serviceName">
        <el-input v-model="dataForm.serviceName" placeholder="请输入服务名称" readonly></el-input>
      </el-form-item>
      <el-form-item label="预约日期" prop="reservationDate">
        <el-input v-model="dataForm.reservationDate" placeholder="请输入预约日期" readonly></el-input>
      </el-form-item>
      <el-form-item label="预约时间" prop="reservationTime">
        <el-input v-model="dataForm.reservationTime" placeholder="请输入预约时间" readonly></el-input>
      </el-form-item>
      <el-form-item label="预约状态" prop="status">
        <el-input v-model="dataForm.status" placeholder="请输入预约状态" readonly></el-input>
      </el-form-item>
      <el-form-item label="客户留言" prop="note">
        <el-input type="textarea" :rows="4" v-model="dataForm.note" placeholder="请输入客户留言" readonly></el-input>
      </el-form-item>
    </el-form>
    <span slot="footer" class="dialog-footer">
      <el-button @click="visible = false">取消</el-button>
    </span>
  </el-dialog>
</template>

<script>
import { getReservationInfo } from '@/api/reservation/reservation';

const defaultDataForm = {
  id: '',
  userId: '',
  serviceId: '',
  reservationDate: '',
  reservationTime: '',
  status: '',
  note: '',
}

export default {
  data() {
    return {
      dataForm: Object.assign({}, defaultDataForm),
      visible: false,
    }
  },
  methods: {
    init(id) {
      this.dataForm.id = id || 0
      this.visible = true
      this.$nextTick(() => {
        this.$refs['dataForm'].resetFields()
        if (this.dataForm.id) {
          getReservationInfo(this.dataForm.id).then(res => {
            if (res && res.code === 200) {
              this.dataForm.userId = res.data.userId;
              this.dataForm.serviceId = res.data.serviceId;
              this.dataForm.reservationDate = res.data.reservationDate;
              this.dataForm.reservationTime = res.data.reservationTime;
              this.dataForm.status = res.data.status;
              this.dataForm.note = res.data.note;
              this.dataForm.userName = res.data.userName;
              this.dataForm.serviceName = res.data.serviceName;
            }
          })
        }
      })
    },
  }
}
</script>
